using System;
using System.Windows.Input;

namespace FreshMeat.Xaml
{
   public abstract class CommandBase : ICommand
   {
      static int nameCounter;

      protected CommandBase(OperationContext context = null, string name = null)
      {
         Context = context ?? new OperationContext();
         Name = name ?? "cmd" + (++nameCounter);

         Context.Notify(this);
      }

      public abstract void Execute(object parameter);

      public abstract bool CanExecute(object parameter);

      public event EventHandler CanExecuteChanged;

      public void NotifyCanExecuteChanged()
      {
         var handler = CanExecuteChanged;
         if (handler != null)
            handler(this, EventArgs.Empty);
      }

      protected OperationContext Context { get; private set; }

      public string Name { get; private set; }
   }
}